//
//  YLSecurityPasswordViewController.m
//  YLFinanceService
//
//  Created by she1323 on 2017/9/2.
//  Copyright © 2017年 she1323. All rights reserved.
//

#import "YLSecurityPasswordViewController.h"
#import "WHNavBackButton.h"
#import "YLSecurityPasswordViewModel.h"
@interface YLSecurityPasswordViewController ()

@property (weak, nonatomic) IBOutlet UITextField *codeTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
@property (weak, nonatomic) IBOutlet UITextField *surePasswordTextField;
@property (weak, nonatomic) IBOutlet UIButton *sureButton;
@property (nonatomic, strong) YLSecurityPasswordViewModel *viewModel;
@end

@implementation YLSecurityPasswordViewController

- (YLSecurityPasswordViewModel *)viewModel
{
    if (!_viewModel) {
        _viewModel = [[YLSecurityPasswordViewModel alloc] init];
    }
    return _viewModel;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    WHNavBackButton *backButton = [WHNavBackButton navBackButton];
    [backButton setImage:[UIImage imageNamed:@"fanhuijianwhite"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    
    self.title = @"更改安全口令";
    
    [self bindViewModel];
    
   
}

- (IBAction)seePassword:(UIButton *)sender {
    sender.selected = !sender.selected;
    _surePasswordTextField.secureTextEntry = !sender.selected;
}


- (void)bindViewModel
{
    RAC(self.viewModel, code) = _codeTextField.rac_textSignal;
    RAC(self.viewModel, password) = _passwordTextField.rac_textSignal;
    RAC(self.viewModel, surePassword) = _surePasswordTextField.rac_textSignal;
    RAC(_sureButton, enabled) = self.viewModel.sureEnableSiganl;
    
    __weak typeof(self) weakSelf = self;
    [_codeTextField.rac_textSignal subscribeNext:^(NSString * _Nullable x) {
        if (x.length > 6) {
            weakSelf.codeTextField.text = [weakSelf.codeTextField.text substringToIndex:6];
        }
    }];
    [_passwordTextField.rac_textSignal subscribeNext:^(NSString * _Nullable x) {
        if (x.length > 6) {
            weakSelf.passwordTextField.text = [weakSelf.passwordTextField.text substringToIndex:6];
        }
    }];
    [_surePasswordTextField.rac_textSignal subscribeNext:^(NSString * _Nullable x) {
        if (x.length > 6) {
            weakSelf.surePasswordTextField.text = [weakSelf.surePasswordTextField.text substringToIndex:6];
        }
    }];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}


- (void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
//    [self.navigationController.navigationBar setBarStyle:UIBarStyleDefault];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navBackground"]  forBarMetrics:UIBarMetricsDefault];
    // 修改状态栏颜色
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
